<template>
  <div class="activity-category-wrap">
    <h2>活动分类管理</h2>
    <div class="activity-category-group">
      <el-button @click="addCategory">添加分类</el-button>
    </div>
    <div class="activity-category-group">
      <el-table :data="activityCategoryList" style="width: 100%">
        <el-table-column prop="activity_name" label="分类图标" width="180">
          <template slot-scope="scope">
            <img :src="scope.row.activity_category_icon" alt="" />
          </template>
        </el-table-column>
        <el-table-column
          prop="activity_category_name"
          label="分类名称"
          width="180"
        >
        </el-table-column>
        <el-table-column
          prop="activity_category_created_at"
          label="分类创建时间"
          width="180"
        >
        </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button
              size="mini"
              @click="handleCategoryEdit(scope.row.activity_category_id)"
              >编辑</el-button
            >
            <el-button
              size="mini"
              type="danger"
              @click="handleCategoryDelete(scope.row.activity_category_id)"
              >删除</el-button
            >
          </template>
        </el-table-column>
      </el-table>

      <el-pagination
        background
        layout="prev, pager, next"
        :total="totalCount"
        @current-change="currentChange"
      />
    </div>
  </div>
</template>
<script>
// import {
//   getActivityCategoryCountApi,
//   getActivityCategoryListApi,
//   addActivityCategoryApi,
//   editActivityCategoryApi,
//   delActivityCategoryApi,
// } from "../http/activityApi";

export default {
  name: "ActivityCategory",
  data() {
    return {
      activityCategoryList: [],
      totalCount: 0,
      currentPage: 1,
      pageSize: 20,
    };
  },
  created() {
    this.getInit(this.currentPage, this.pageSize);
  },
  methods: {
    getInit(currentPage, pageSize) {
      console.log(currentPage, pageSize);
      // getActivityCategoryCountApi()
      //   .then((res) => {})
      //   .catch((err) => {
      //     console.log("获取分页总数出错：", err);
      //   });
      // getActivityCategoryListApi(currentPage, pageSize)
      //   .then((res) => {
      //     this.activityCategoryList = res.data.data;
      //   })
      //   .catch((err) => {
      //     console.log("获取分页总数出错：", err);
      //   });
    },
    currentChange(currentPage) {
      this.currentPage = currentPage;

      this.getInit(currentPage, this.pageSize);
    },
    addCategory() {
      // addActivityCategoryApi();
    },
    handleCategoryEdit(id) {
      console.log(id);
      // editActivityCategoryApi();
    },
    handleCategoryDelete(id) {
      this.$confirm("此操作将永久删除该数据, 是否继续?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "error",
      })
        .then(() => {
          console.log("确认");
          this.delActivityCategory(id);
        })
        .catch(() => {
          console.log("取消");
        });
    },
    delActivityCategory(id) {
      console.log(id);
      // delActivityCategoryApi(id);
    },
  },
};
</script>

<style lang="scss" scoped>
.activity-category-wrap {
  h2 {
    padding: 10px 0;
  }
  .activity-category-group {
    margin-bottom: 10px;
  }
}
</style>